<?php

namespace app\api\controller\im;

use app\common\controller\Frontend;
use think\facade\Log;
use app\common\enum\LogChannelEnum;

class Base extends Frontend
{
    protected array $noNeedLogin = [];
    protected array $noNeedPermission = [];

    public function initialize(): void
    {
        parent::initialize();
    }

    protected function log($info = '')
    {
        Log::channel(LogChannelEnum::IM)->info($info);
    }

    protected function check($validate, $params){
        // 使用验证器的创建场景进行参数验证，如果验证失败则抛出异常
        try {
            $validate->scene('create')->check($params);
        } catch (\Throwable $e) {
            Log::channel(LogChannelEnum::IM)->error($e->getMessage() . PHP_EOL . $e->getTraceAsString());
            // 如果验证失败，显示错误消息
            $this->error($e->getMessage());
        }
    }
}